What Are The Trends In Planted Trees By Year?
What Are The Trends In Planted Trees By Year?#
Looking at the chart below, it is apparent that maple trees were the tree of choice when being planted. There is a big spike in planted maple trees starting in 1991 but start to decline in 2013. Cherry and Plum trees increased increase slowly over the time period and following the downward trend in 2013 and 2012 respectively. There is no indication on why there is a drop or increase for that matter, but I wonder if there was just no need for more of these types of trees in Vancouver.
# Import libraries needed for this assignment
from hashlib import sha1
import altair as alt
import pandas as pd
from vega_datasets import data
import numpy as np
alt.data_transformers.enable("default", max_rows=None)
# Importing the data
url='https://raw.githubusercontent.com/UBC-MDS/exploratory-data-viz/main/data/street_trees.csv'
street_trees_df = pd.read_csv(url, sep=';')
# Filtered dataframe that includes relevant columns and rows as well as newly created columns
trees_df=street_trees_df.drop(['TREE_ID', 'CIVIC_NUMBER', 'STD_STREET','CULTIVAR_NAME','ASSIGNED','ROOT_BARRIER','PLANT_AREA','ON_STREET_BLOCK','ON_STREET','STREET_SIDE_NAME','CURB','Geom'], axis=1)
trees_df = trees_df[trees_df['GENUS_NAME'].isin(['ACER', 'PRUNUS'])]
trees_df=trees_df.assign(YEAR_PLANTED=np.where(trees_df.DATE_PLANTED=='Nat','N/A', trees_df['DATE_PLANTED'].str[:4]))
trees_df.loc[:,'TREE_TYPE']=np.where((trees_df.COMMON_NAME.str.contains('MAPLE')), 'MAPLE',np.where((trees_df.COMMON_NAME.str.contains('CHERRY')), 'CHERRY',
np.where((trees_df.COMMON_NAME.str.contains('PLUM')),'PLUM','OTHER')))
no_nulls_df = pd.notnull(trees_df['YEAR_PLANTED'])
no_nulls_df=trees_df[no_nulls_df]
# Create chart
select_tree_type = alt.selection_multi(fields=['TREE_TYPE'],bind='legend')
planted_trees_by_year_chart=alt.Chart(no_nulls_df).mark_line().encode(
alt.X('YEAR_PLANTED'),
alt.Y('count()'),
color='TREE_TYPE').properties(title='Trends in Trees Planted: 1998-2019',width=500, height=400)
planted_trees_by_year_pt_chart=alt.Chart(no_nulls_df).mark_point().encode(
alt.X('YEAR_PLANTED', title='Year'),
alt.Y('count()', title='Tree Count'),
alt.Color('TREE_TYPE', title = 'Tree Type'),
tooltip=[alt.Tooltip('GENUS_NAME', title='Genus'), alt.Tooltip('TREE_TYPE', title='Tree Type'), alt.Tooltip('count()', title='Count')]
).properties(width=500, height=400)
(planted_trees_by_year_chart + planted_trees_by_year_pt_chart)#.add_selection(select_tree_type)